package com.base.cn.platform.os.common.mybatis;

import com.base.cn.platform.os.entity.manage.subject.SysSubject;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.net.URLDecoder;
import java.util.List;
import java.util.Map;

@Data
@EqualsAndHashCode(callSuper = false)
@Slf4j
public class BaseEntity extends IEntity{
    /**图片JSON内容*/
    private String imageJson;
    /**把编码形式的图片内容转成的Map对象*/
    private Map<String,Object> imageMap;
    /**员操管理作ID*/
    private BigDecimal createUserId;
    /**创建管理员对象数据*/
    private Map<String,Object> createUser;
    /**专业ID串*/
    private String subjectIds;
    /**专业列表*/
    private List<SysSubject> subjectList;
    /**租户ID*/
    private BigDecimal tenantId;

    public Map<String,Object> getImageMap(){
        if(this.imageMap !=null){
            return this.imageMap;
        }
        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
        String imageJson = this.getImageJson();
        if(imageJson!=null && !imageJson.trim().equals("")){
            try{
                imageJson = URLDecoder.decode(imageJson,"utf-8");
            }catch (Exception e){
                log.error("--------------------图片转换错误");
            }
            this.imageMap = gson.fromJson(imageJson,new TypeToken<Map<String,Object>>(){}.getType());
            return this.imageMap;
        }
        return null;
    }
}
